import _ from 'lodash';

export const getWeekList = startDate => {

  const weekList = [];
  let endDate = new Date();

  startDate.setDate(startDate.getDate() - startDate.getDay() + 1);

  if (endDate.getDay() === 0) {
    endDate = endDate;
  } else {
    endDate.setDate(endDate.getDate() + 7 - endDate.getDay());
  }

  let localEndDate = new Date(startDate);
  localEndDate.setDate(localEndDate.getDate() + 6);
  let localStartDdate = _.cloneDeep(startDate);

  while (localEndDate.getTime() <= endDate.getTime()) {
    weekList.push({
      start: _.cloneDeep(localStartDdate),
      end: _.cloneDeep(localEndDate)
    });

    localStartDdate.setDate(localStartDdate.getDate() + 7);
    localEndDate.setDate(localEndDate.getDate() + 7);
  }

  return weekList;
}